Skip to content

[Workflows] support passing attachments to run_agent step#251291

Merged
KDKHD merged 15 commits intoelastic:mainfrom
KDKHD:feature/workflow_run_agent_attachments
Feb 24, 2026
Merged

[Workflows] support passing attachments to run_agent step#251291
KDKHD merged 15 commits intoelastic:mainfrom
KDKHD:feature/workflow_run_agent_attachments

Conversation

@KDKHD
Copy link
Copy Markdown
Member

@KDKHD KDKHD commented Feb 2, 2026

Summary

Summarize your PR. If it involves visual changes include a screenshot or gif.

Add support for passing attachments to the run agent step in workflows.

image image

Example workflow with alert attachment

name: New workflow
enabled: false
description: This is a new workflow
triggers:
  - type: alert

steps:
  - name: ai_agent_step
    type: ai.agent
    connector-id: "<connector_id>"
    with:
      message: "Summarise these alert"
      attachments:
        - type: security.alert
          data:
            alert: "{{event.alerts | json:2}}"
            attachmentLabel: "Alert attachment."

PR also moves attachment validation down into ExecutionService so that attachments passed via workflows are validated.

Checklist

Check the PR satisfies following conditions.

Reviewers should verify this PR satisfies this list as well.

  • Any text added follows EUI's writing guidelines, uses sentence case text and includes i18n support
  • Documentation was added for features that require explanation or tutorials
  • Unit or functional tests were updated or added to match the most common scenarios
  • If a plugin configuration key changed, check if it needs to be allowlisted in the cloud and added to the docker list
  • This was checked for breaking HTTP API changes, and any breaking changes have been approved by the breaking-change committee. The release_note:breaking label should be applied in these situations.
  • Flaky Test Runner was used on any tests changed
  • The PR description includes the appropriate Release Notes section, and the correct release_note:* label is applied per the guidelines
  • Review the backport guidelines and apply applicable backport:* labels.

Identify risks

Does this PR introduce any risks? For example, consider risks like hard to test bugs, performance regression, potential of data loss.

Describe the risk, its severity, and mitigation for each identified risk. Invite stakeholders and evaluate how to proceed before merging.

@KDKHD KDKHD marked this pull request as ready for review February 2, 2026 17:09
@KDKHD KDKHD requested a review from a team as a code owner February 2, 2026 17:09
@KDKHD KDKHD changed the title [Workflows] support attachments in run_agent step [Workflows] support passing attachments in run_agent step Feb 2, 2026
@KDKHD KDKHD changed the title [Workflows] support passing attachments in run_agent step [Workflows] support passing attachments to run_agent step Feb 2, 2026
@KDKHD KDKHD added release_note:skip Skip the PR/issue when compiling release notes backport:skip This PR does not require backporting labels Feb 2, 2026
Copy link
Copy Markdown
Contributor

@pgayvallet pgayvallet left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Feature makes sense, thanks for adding that.

There's only one thing we need to address, about attachment validation - added a specific comment below.

outputSchema: schema,
nextInput: {
message,
attachments,
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We're going to have a problem with the way attachment validation currently work.

Atm, validation is done in the converse route handler directly (which is pretty bad - agreed). This was "fine" because before this PR, the converse API was the only entry point for attachments, so for their validation.

const validateAttachments = async ({
attachments,
attachmentsService,
}: {
attachments: AttachmentInput[];
attachmentsService: AttachmentServiceStart;
}) => {
const results: AttachmentInput[] = [];
for (const attachment of attachments) {
const validation = await attachmentsService.validate(attachment);
if (validation.valid) {
results.push(validation.attachment);
} else {
throw createBadRequestError(`Attachment validation failed: ${validation.error}`);
}
}
return results;
};

So passing attachments directly to chatService.converse as done here bypass this validation.

But now we need to find a way to address that, either by:

  1. moving the validation which is currently living in the converse route handler a few layers down, either in chatService or even lower in the chain, so that we hit the attachment validation when calling an agent via that workflow step (probably the most robust way, even if more work - there might be a few type issues between Attachment vs AttachmentInput)
  2. extract / re-use the logic we use from the route handler in the step definition - move that validateAttachments living in the handler file elsewhere, and then re-use it from the step definition (I would be fine with that too)
  3. re-use the "attachment state manager" we use for the attachment routes (x-pack/platform/plugins/shared/agent_builder/server/routes/attachments.ts). It doesn't have an API for validation atm, but it has an internal validateAttachmentData function. we could add a new public "validateAttachment" which would reproduce the logic of what we do in validateAttachments` in the converse route handler today, and then use this in the step definition and in the route (seems like a good compromise)

Fine with either, you can pick.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Moved into ExecutionService since ChatService has been removed.

@KDKHD KDKHD requested a review from a team as a code owner February 4, 2026 11:36
@KDKHD
Copy link
Copy Markdown
Member Author

KDKHD commented Feb 11, 2026

@elasticmachine merge upstream

@elasticmachine
Copy link
Copy Markdown
Contributor

merge conflict between base and head

@botelastic botelastic Bot added the Team:One Workflow Team label for One Workflow (Workflow automation) label Feb 18, 2026
),
});

const validateAttachments = async ({
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Moved attachment validation down into the execution service.

@talboren talboren removed the Team:One Workflow Team label for One Workflow (Workflow automation) label Feb 23, 2026
@KDKHD
Copy link
Copy Markdown
Member Author

KDKHD commented Feb 23, 2026

@elasticmachine merge upstream

@botelastic botelastic Bot added the Team:One Workflow Team label for One Workflow (Workflow automation) label Feb 23, 2026
@elasticmachine
Copy link
Copy Markdown
Contributor

💛 Build succeeded, but was flaky

Failed CI Steps

Test Failures

  • [job] [logs] Jest Tests #9 / Header QueryTabHeader should render the immutable timeline call out providers
  • [job] [logs] Jest Tests #9 / Header QueryTabHeader should render the immutable timeline call out with correct message

Metrics [docs]

Page load bundle

Size of the bundles that are downloaded on every page load. Target size is below 100kb

id before after diff
agentBuilder 86.8KB 87.0KB +162.0B
Unknown metric groups

References to deprecated APIs

id before after diff
agentBuilder 38 41 +3

Unreferenced deprecated APIs

id before after diff
agentBuilder 38 41 +3

History

@KDKHD KDKHD requested a review from shahargl February 23, 2026 13:36
Copy link
Copy Markdown
Contributor

@shahargl shahargl left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm

@KDKHD KDKHD merged commit 881b463 into elastic:main Feb 24, 2026
17 checks passed
mbondyra added a commit to rgodfrey-elastic/kibana that referenced this pull request Feb 24, 2026
…ps-config-rebase

* commit 'f135f030951237c5e9b0251931441aee3121b31d': (163 commits)
  [CPS] Support data view requests and do not sanitize project_routing in data plugin/resolve indices  (elastic#253654)
  [One Workflow] Execute workflow from historical (elastic#253396)
  [streams][background tasks] gracefully handle non existing stream (elastic#254683)
  [Lens API] Waffle/Mosaic get green as a default color (elastic#254304)
  [Security Solution] Remove prebuilt rules customization callout on Rule Management page (elastic#254386)
  [Workflows] support passing attachments to run_agent step (elastic#251291)
  [One Discover][Logs UX] Update OpenTelemetry Semantic Conventions (elastic#254367)
  [kbn-es] Add --docker flag to yarn es snapshot (elastic#254306)
  [Workplace AI] Remove Data Source Config (elastic#254521)
  [Entity Store v2] Add CRUD API (elastic#252052)
  [CI] Increase type checking machine (elastic#254676)
  [main] Sync bundled packages with Package Storage (elastic#254232)
  Skip flaky test elastic#254625 (elastic#254662)
  Upgrade `@elastic/elasticsearch` to 9.3.1 (elastic#253660)
  [One Workflow] Migrate http step to new connector (elastic#249004)
  [Entity Store] Store EUID Scripts (elastic#254515)
  [APM] Fix Otel missing fields undefined errors (elastic#254271)
  [Console] Add support for documentation links on Serverless (elastic#254489)
  Create edit ILM flow (elastic#253393)
  [Agent Builder] Mid term: minimal recommended model set elastic#12875 (elastic#254560)
  ...
nreese pushed a commit to nreese/kibana that referenced this pull request Feb 25, 2026
…1291)

## Summary

Summarize your PR. If it involves visual changes include a screenshot or
gif.

Add support for passing attachments to the run agent step in workflows.

<img width="3355" height="1040" alt="image"
src="https://github.com/user-attachments/assets/1890761d-6e17-4746-b9fd-0b40e89983a8"
/>

<img width="2180" height="615" alt="image"
src="https://github.com/user-attachments/assets/60f1675b-89a8-4fb5-9c14-0ce16efdb0ff"
/>

Example workflow with alert attachment
```
name: New workflow
enabled: false
description: This is a new workflow
triggers:
  - type: alert

steps:
  - name: ai_agent_step
    type: ai.agent
    connector-id: "<connector_id>"
    with:
      message: "Summarise these alert"
      attachments:
        - type: security.alert
          data:
            alert: "{{event.alerts | json:2}}"
            attachmentLabel: "Alert attachment."
```

PR also moves attachment validation down into ExecutionService so that
attachments passed via workflows are validated.

### Checklist

Check the PR satisfies following conditions. 

Reviewers should verify this PR satisfies this list as well.

- [X] Any text added follows [EUI's writing
guidelines](https://elastic.github.io/eui/#/guidelines/writing), uses
sentence case text and includes [i18n
support](https://github.com/elastic/kibana/blob/main/src/platform/packages/shared/kbn-i18n/README.md)
- [X]
[Documentation](https://www.elastic.co/guide/en/kibana/master/development-documentation.html)
was added for features that require explanation or tutorials
- [X] [Unit or functional
tests](https://www.elastic.co/guide/en/kibana/master/development-tests.html)
were updated or added to match the most common scenarios
- [X] If a plugin configuration key changed, check if it needs to be
allowlisted in the cloud and added to the [docker
list](https://github.com/elastic/kibana/blob/main/src/dev/build/tasks/os_packages/docker_generator/resources/base/bin/kibana-docker)
- [X] This was checked for breaking HTTP API changes, and any breaking
changes have been approved by the breaking-change committee. The
`release_note:breaking` label should be applied in these situations.
- [X] [Flaky Test
Runner](https://ci-stats.kibana.dev/trigger_flaky_test_runner/1) was
used on any tests changed
- [X] The PR description includes the appropriate Release Notes section,
and the correct `release_note:*` label is applied per the
[guidelines](https://www.elastic.co/guide/en/kibana/master/contributing.html#kibana-release-notes-process)
- [X] Review the [backport
guidelines](https://docs.google.com/document/d/1VyN5k91e5OVumlc0Gb9RPa3h1ewuPE705nRtioPiTvY/edit?usp=sharing)
and apply applicable `backport:*` labels.

### Identify risks

Does this PR introduce any risks? For example, consider risks like hard
to test bugs, performance regression, potential of data loss.

Describe the risk, its severity, and mitigation for each identified
risk. Invite stakeholders and evaluate how to proceed before merging.

- [ ] [See some risk
examples](https://github.com/elastic/kibana/blob/main/RISK_MATRIX.mdx)
- [ ] ...

---------

Co-authored-by: kibanamachine <42973632+kibanamachine@users.noreply.github.com>
Co-authored-by: Elastic Machine <elasticmachine@users.noreply.github.com>
qn895 pushed a commit to qn895/kibana that referenced this pull request Mar 11, 2026
…1291)

## Summary

Summarize your PR. If it involves visual changes include a screenshot or
gif.

Add support for passing attachments to the run agent step in workflows.

<img width="3355" height="1040" alt="image"
src="https://github.com/user-attachments/assets/1890761d-6e17-4746-b9fd-0b40e89983a8"
/>

<img width="2180" height="615" alt="image"
src="https://github.com/user-attachments/assets/60f1675b-89a8-4fb5-9c14-0ce16efdb0ff"
/>

Example workflow with alert attachment
```
name: New workflow
enabled: false
description: This is a new workflow
triggers:
  - type: alert

steps:
  - name: ai_agent_step
    type: ai.agent
    connector-id: "<connector_id>"
    with:
      message: "Summarise these alert"
      attachments:
        - type: security.alert
          data:
            alert: "{{event.alerts | json:2}}"
            attachmentLabel: "Alert attachment."
```

PR also moves attachment validation down into ExecutionService so that
attachments passed via workflows are validated.

### Checklist

Check the PR satisfies following conditions. 

Reviewers should verify this PR satisfies this list as well.

- [X] Any text added follows [EUI's writing
guidelines](https://elastic.github.io/eui/#/guidelines/writing), uses
sentence case text and includes [i18n
support](https://github.com/elastic/kibana/blob/main/src/platform/packages/shared/kbn-i18n/README.md)
- [X]
[Documentation](https://www.elastic.co/guide/en/kibana/master/development-documentation.html)
was added for features that require explanation or tutorials
- [X] [Unit or functional
tests](https://www.elastic.co/guide/en/kibana/master/development-tests.html)
were updated or added to match the most common scenarios
- [X] If a plugin configuration key changed, check if it needs to be
allowlisted in the cloud and added to the [docker
list](https://github.com/elastic/kibana/blob/main/src/dev/build/tasks/os_packages/docker_generator/resources/base/bin/kibana-docker)
- [X] This was checked for breaking HTTP API changes, and any breaking
changes have been approved by the breaking-change committee. The
`release_note:breaking` label should be applied in these situations.
- [X] [Flaky Test
Runner](https://ci-stats.kibana.dev/trigger_flaky_test_runner/1) was
used on any tests changed
- [X] The PR description includes the appropriate Release Notes section,
and the correct `release_note:*` label is applied per the
[guidelines](https://www.elastic.co/guide/en/kibana/master/contributing.html#kibana-release-notes-process)
- [X] Review the [backport
guidelines](https://docs.google.com/document/d/1VyN5k91e5OVumlc0Gb9RPa3h1ewuPE705nRtioPiTvY/edit?usp=sharing)
and apply applicable `backport:*` labels.

### Identify risks

Does this PR introduce any risks? For example, consider risks like hard
to test bugs, performance regression, potential of data loss.

Describe the risk, its severity, and mitigation for each identified
risk. Invite stakeholders and evaluate how to proceed before merging.

- [ ] [See some risk
examples](https://github.com/elastic/kibana/blob/main/RISK_MATRIX.mdx)
- [ ] ...

---------

Co-authored-by: kibanamachine <42973632+kibanamachine@users.noreply.github.com>
Co-authored-by: Elastic Machine <elasticmachine@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

backport:skip This PR does not require backporting release_note:skip Skip the PR/issue when compiling release notes Team:One Workflow Team label for One Workflow (Workflow automation) v9.4.0

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants